package logic

import (
	"an_ju_ke/models"
	"an_ju_ke/pkg"
	"context"
	"fmt"
	"time"

	"an_ju_ke/myrpc/internal/svc"
	"an_ju_ke/myrpc/myrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ImageLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewImageLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ImageLogic {
	return &ImageLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ImageLogic) Image(in *myrpc.ImageRequest) (*myrpc.ImageResponse, error) {
	// todo: add your logic here and delete this line
	key := fmt.Sprintf("image_captcha_user_name:%s", in.UserName)
	image, code := pkg.ImageCaptcha()
	models.Rdb.Set(models.Ctx, key, code, 3*time.Minute)
	return &myrpc.ImageResponse{
		Image: image,
	}, nil
}
